package com.huike.web.controller.report;


import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.common.utils.SecurityUtils;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import com.huike.report.domain.vo.PieChartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    /**
     * 首页--商机转化龙虎榜
     *
     * @param request
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(IndexStatisticsVo request) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime() + " 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime() + " 23:59:59");
        List<Map<String, Object>> list = reportService.businessChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }

    /**
     * 首页--线索转化龙虎榜
     *
     * @param request
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistics(IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= reportService.clueChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }

    /**
     * 首页--今日新增线索 商机 合同 销售额
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){
        //补全信息
        //1.设置当前日期
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        //2.获取当前登录用户
        String username = SecurityUtils.getUsername();
        //3.调用service
        IndexTodayInfoVO indexTodayInfoVO = reportService.getTodayInfo(today,username);
        return AjaxResult.success(indexTodayInfoVO);

    }

    /**
     * 首页--待办事项
     * /index/getTodoInfo?beginCreateTime=2022-05-05&endCreateTime=2023-05-05
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        //0.补全信息
        String username = SecurityUtils.getUsername();
        //1.调用service层
        IndexTodoInfoVO indexTodoInfoVO = reportService.getTodoInfo(username, beginCreateTime,endCreateTime);
        //2.返回参数
        return AjaxResult.success(indexTodoInfoVO);
    }


}